using System;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace RPGOnline.Remoting.Entities
{
    [DataContract]
    public class RollResult
    {
        [DataMember]
        public int HowMany { get; private set; }
        [DataMember]
        public int DieSides { get; private set; }
        [DataMember]
        public int Modifiers { get; private set; }
        [DataMember]
        public int Result { get; private set; }
        [DataMember]
        public List<int> RollResults { get; private set; }

        public RollResult(int howMany, int dieSides, int modifiers)
        {
            HowMany = howMany;
            DieSides = dieSides;
            Modifiers = modifiers;
            Result = modifiers;
            RollResults = new List<int>();
        }

        public RollResult(int howMany, int dieSides, int modifiers, int result)
        {
            HowMany = howMany;
            DieSides = dieSides;
            Modifiers = modifiers;
            Result = result;
            RollResults = new List<int>();
        }

        public override string ToString()
        {
            string modifiersString = Modifiers == 0 ? "" : (Modifiers > 0) ? "+" + Modifiers : Modifiers.ToString();
            return string.Format("{0}d{1}{2} = {3}", HowMany, DieSides, modifiersString, Result);
        }

        public void AddRoll(int dieRoll)
        {
            Result += dieRoll;
            RollResults.Add(dieRoll);
        }
    }
}